﻿        
function NullToValue(pValue,pDefValue){
        if(pValue == "null"){
            return pDefValue;
        }else{
            return pValue;
        }    
}

//Selecciona un valor de un combo
function SetValueFromDropList(ComboName, Value){
    var oCmb = document.getElementById(ComboName);
    for(var i=0;i < oCmb.length;i++){      
      if(oCmb.options[i].value == Value){
        oCmb.selectedIndex = i;
        break;
      }            
    }                                                   
}

function AbrirNoModal(pagina,width,heigth,FrmNombre,SinEstados){
    var dialogHeight = 750;
    var dialogWidth = 550;
    
    if(width != null){
        dialogWidth = width;
    }
    if(heigth != null){
        dialogHeight = heigth;
    }
    var Parametros = "";
    if(SinEstados != null){
        if(SinEstados == true){
            Parametros ="resizable=yes,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";
        }
    }
    var oWindow = window.open(pagina,FrmNombre,Parametros);
}

//Abre una ventana modal
function AbrirModal(titulo, pagina, selector,width,heigth,filtros){
    var dialogHeight = 750;
    var dialogWidth = 550;
    
    if(width != null){
        dialogWidth = width;
    }
    if(heigth != null){
        dialogHeight = heigth;
    }

     var strFeatures = "dialogWidth="+dialogWidth+"px;dialogHeight="+dialogHeight+"px; center=yes; help=no;";
     var objNewWindow = window.showModalDialog("../WebControls/FrmContenedorModal.aspx?tittle="+titulo+"&pagina=" + pagina + "&Selector=" + selector+"&filtros=" + filtros ,window,strFeatures);
     
}

function AgregarFila(gridName)
{
    igtbl_addNew(gridName,0);
}

function DeleteRow(GridId){
  var objRowSel = igtbl_getActiveRow(GridId);	
  var grid=igtbl_getGridById(GridId);
  var removedRow=grid.Rows.remove(objRowSel.getIndex());  
}  

function ExisteElementoEnGrilla(gridName, columna, valor)
    
    {
    if (valor == 0)
    {
        return false;
    }
    var objGrid = igtbl_getGridById(gridName);
			var row = objGrid.Rows.getRow(0);
			var encontrado = false;
            while (row!=null)
			{
				var cell = row.getCellFromKey(columna);
				if (valor==cell.getValue())
				{
				    encontrado = true;
				    break;
				}
				else
				{
				    encontrado = false;
				}
				
				row = row.getNextRow();
			}
			return encontrado;
    }

        function ObtenerParametros(Key)
        {
            var qsParm = new Array();
            var query = window.location.search.substring(1);            
            var parms = query.split('&');
            for (var i=0; i<parms.length; i++) {
                var pos = parms[i].indexOf('=');
                if (pos > 0) {
                    var key = parms[i].substring(0,pos);
                    var val = parms[i].substring(pos+1);
                    qsParm[key] = val;
                }
            }
            return qsParm[Key];
        }

//Función para ocultar o mostrar una fila de tabla
function cambiarDisplay(id, btnid) {
        if (!document.getElementById) return false;
            fila = window.document.getElementById(id);
            boton = window.document.getElementById (btnid);
        if (fila.style.display != "none") {
            fila.style.display = "none"; //ocultar fila
            fila.style.visibility = "hidden";
            boton.value = "+";
            }     
        else {
            fila.style.display = ""; //mostrar fila
            fila.style.visibility = "";
            boton.value="-";
            }
      }

 index = 0;
 
 function TransformEnter(){
          document.onkeydown = Tecla; 
          if (document.captureEvents)       
            document.captureEvents(Event.KEYDOWN)                    
        }
        
        function Tecla(e){
          if ( window.event != null)            //IE4+
            t = window.event.keyCode;
          else if ( e != null )             //N4+ o W3C compatibles
            t = e.which;
          else
            return;
                      
          if (t == 13) {                //se pulso enter    
            if (index == -1 ) {         //fin de la secuencia, hace el submit                  
              return true               
            } else {                   //da el foco al siguiente campo        
              window.event.keyCode = 9;
              return window.event.keyCode;             
            }
          }
        
        }

function GetCode(e){
  if ( window.event != null)            //IE4+
    t = window.event.keyCode;
  else if ( e != null )             //N4+ o W3C compatibles
    t = e.which;
  else
    return;
}
    //Pone invisible el control pasado
    function HiddenObject(obj){
      document.getElementById(obj).style.display='none';
      document.getElementById(obj).style.visibility='hidden';      
    }

    //Pone visible el control pasado
    function ShowObject(obj,pDisplay){    
      document.getElementById(obj).style.visibility='visible';      
      if(pDisplay != null){
        document.getElementById(obj).style.display= pDisplay;
      }else{
        document.getElementById(obj).style.display= 'block';
      }      
    }

    // Habilita y deshabilita controles..
    function Habilitar(Chk,Control1,Control2){           
      ctrl1 = document.getElementById(Control1);

      if((ctrl1 != null) && (ctrl1.type != "hidden")){        
        ctrl1.disabled = !document.getElementById(Chk).checked;
      }else{          
        ctrl1 = igedit_getById(Control1);                       
        ctrl1.setEnabled(document.getElementById(Chk).checked);        
      }
      
      if(Control2 != ""){
        ctrl2 = document.getElementById(Control2);
        if((ctrl2 != null) && (ctrl2.type != "hidden")){
            ctrl2.disabled = !document.getElementById(Chk).checked;
        }else{
          ctrl2 = igedit_getById(Control2);                       
          ctrl2.setEnabled(document.getElementById(Chk).checked);        
        }        
      }
    }

   // Oculta tabla html, seteando los estilos
   function OcultarTabla(btn,tbl){
     var oCtrl = null;
     if(window.parent.frmHeader != null){
        oCtrl = window.parent.frmHeader.document.getElementById('HdnStatusFilter'); 
     }
     if(oCtrl != null){
       oCtrl.value = document.getElementById(btn).value;
     }

     if(document.getElementById(btn).value === "-"){
        document.getElementById(tbl).style.visibility ="hidden";
		document.getElementById(tbl).style.display = "none";
		document.getElementById(btn).value = "+";
     }else{
        document.getElementById(tbl).style.visibility ="visible";
		document.getElementById(tbl).style.display = "";
		document.getElementById(btn).value = "-";
     }         
     // Finalmente, guardo el estado...
     
   }

   function ProcessMessage(){
     return "<table style='width:100%'><tr><td style='width:100%' align='center'><img  src='../Images/loading2.gif' /></td></tr></table>";
   }
   
   function IsLess(ctrl){
        return (ctrl.value.length < 1024)
   }

   function FormatObserv(ctrl){
     if(!IsLess(ctrl)){     
        ctrl.value = ctrl.value.substr(0,1024);
     }        
   }

function IsFacNumeric(sText)
{
   var ValidChars = "0123456789-";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function ShowMessage(pMsg,pTittle,pIcon){
	if(pTittle===undefined){
		pTittle = "Mensaje";
	}
	if(pIcon===undefined){
		pIcon = "ext-mb-warning";
	}
	Ext.MessageBox.show({
           title: pTittle,
           msg: pMsg,
           buttons: Ext.MessageBox.OK,       		   
           icon: pIcon
       });
}

function Confirmar(Msg,funcion){
    Ext.MessageBox.confirm('Confirmaci&oacute;n', Msg, funcion);
}

function ShowNoPermiso(){
	ShowMessage("No tiene permiso para realizar esta operaci&oacute;n. Consulte con su administrador de sistemas o verifique las directivas de seguridad asignadas.", "Seguridad","ext-mb-error");
}

function BlockPage(pMsg,pProgressText,pType){
	if(pMsg==null){
		pMsg='Procesando, por favor aguarde...';
	}
	if(pProgressText==null){
		pProgressText='Guardando...';
	}
	if(pType==null){
		pType=1;
	}
	
	switch(pType){
		case 1: 
			pIcon = 'ext-mb-download'; 
			break;
	}
	
	var Id=Math.floor(Math.random()*101);
	Ext.MessageBox.show({
	   id: "WinProgress"+Id,
	   msg: pMsg,
	   progressText: pProgressText,
	   width:300,
	   height: 100,
	   wait:true,
	   waitConfig: {interval:200},
	   reset: true,
	   icon:pIcon //custom class in msg-box.html
	   //animEl: 'mb7'
   });
}

function UnBlockPage(){
	Ext.MessageBox.hide();
}

function NewForm(AForm, ATittle, AWidth, AHeight,functionClose){
	var Id=Math.floor(Math.random()*101);

	Ext.onReady(function() {
	    var MyWindow = new Ext.Window({
			id: "MyWindow"+Id,
	        title: ATittle,
	        width: AWidth,
	        height: AHeight,
	        minWidth: AWidth,
	        minHeight: AHeight,			
	        layout: 'form',
			modal: true,
	        plain: true,
			reset: true,
	        //bodyStyle:'padding:5px;',
	        buttonAlign:'center',
	        html: "<iframe src='"+AForm+"' width='100%' height='"+AHeight+"px' frameborder='0'  MARGINHEIGHT='0' LEFTMARGIN='0' TOPMARGIN='0'  ></iframe>"
	    });
	    
	    if(functionClose != null){
	        MyWindow.on('hide', functionClose); 
	    }
	    MyWindow.show();
	    
	});
}

function setValueRadio(pName,pValue){
	var oRadio = document.forms[0].elements[pName];
	for (var i=0;i<oRadio.length;i++){ 
		if (oRadio[i].value == pValue){ 
			oRadio[i].checked = true;
			return;
		} 
	} 
}

function getValueRadio(pName){
	var oRadio = document.forms[0].elements[pName];
	for (var i=0;i<oRadio.length;i++){ 
		if (oRadio[i].checked){ 
			return  oRadio[i].value; 
		} 
	} 
}

function CerrarVentana(){
    Ext.onReady(function() {
        if(Ext == null){
            window.parent.Ext.WindowMgr.getActive().hide();
        }else{
            Ext.WindowMgr.getActive().hide();
        }        
    })
}

function CreatePanel(pName,pCapaHtml,pTittle){
    Ext.onReady(function(){
        var p = new Ext.Panel({title: pTittle,collapsible:true,region: pCapaHtml,width:'100%',renderTo: pName,contentEl: pCapaHtml});
    });
}

function OcultarObject(pObj){
    document.getElementById(pObj).style.visibility ="hidden";
    document.getElementById(pObj).style.display = "none";
}

function MostrarObject(pObj){
    document.getElementById(pObj).style.visibility ="visible";
    document.getElementById(pObj).style.display = "";
}
